<!-- 促销计划 -->
<template name='sales_plan'>	
<view style="display: flex;    height: 100%;">
		<!-- 商品信息-右边 -->
			<view class="box-infos font12 " >
			
			<!-- 列表区 -->
			<view class="content-box" >
				<view class="boxsss" >
					<!-- 增加、删除 -->
					<view class="top-but">
						<view class="top-but-box">
						
							<view @click="addShow('')" class="add_color but-add" >
								<img src="../../static/img/add.png" class="img"></img>
								增加计划
							</view>
							<text selectable="true"  class="tipss">用于商城的满送活动；常用于轮胎混合送其一的活动！只限于同一张单的下单内容。不累计不累积！</text>
							<view @click="$common.noMultipleClicks('getPlanMaxOut',getPlanMaxOut,true)" 
							class="rightButttom" >
								<img src="../../static/img/update.png" class="ico"></img>
								刷新
							</view>
						</view>
					</view>
					
					<table v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th  class="centers " style="min-width: 20px;">
									序
								</th>
								<th  >
									计划名
								</th>
							
								<th  class=" ">
									备注
								</th>
								<th  class="centers">
									开始时间
								</th>
								<th  class="centers">
									结束时间
								</th>
								<th  class="centers">
									状态
								</th>
								<th  class="centers">
									操作者
								</th>
								<th  class="centers">
									操作
								</th>
							</tr>
						</thead>
						<tbody>
							<!-- 内容 -->
							<tr  
							:key="index" 
							@click="TabcheckedIndex=index"
							v-for="(item,index) in resData.list" 
							:class="TabcheckedIndex == index ? 'goods-list-select':''"
							:style="item.status==1 ?'color: #e40318;':''"
							>
								<td  class="centers ">
									{{index+1}}
								</td>
								<td   class=" " >
									{{item.nickname}}
								</td>
								
								<td   class="" >
									{{item.descr}}
								</td>
								<td class="centers   ">
									{{timestampToDate(item.start_time)}}
								</td>
								<td class="centers   ">
									{{timestampToDate(item.end_time)}}
								</td>
								<td  class="centers  status0  " v-if="item.status==1 && item.start_time >resData.now_time" >
									未到时间
								</td>
								<td class="centers  status1 font12" v-if="item.status==1 && item.start_time <= resData.now_time">
									<countdown
									style="margin-left: auto;" 
									:startTime="resData.now_time" 
									:endTime="item.end_time" 
									v-if="item.status==1" 
									/>
								</td>
								<td class="centers  status2 " v-if="item.status==2">
									已停止
								</td>
								<td class=" status2 centers" >
									{{item.uid_name}}
								</td>
								<td class="centers " >
									<view @click="addShow(item)" class="margin alter centers">
										详细
									</view>
								</td>
							</tr>
						</tbody>
					</table>
					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>
				<!-- 分页 -->
				<pages 
				:sum="page.sum"
				:current="page.nowPage"
				@updatePage="AddUpdatePage"
				></pages>
				<!-- end -->
			</view>
			<!-- end -->

			<!-- 增加/修改  遮罩层 -->
			<uni-popup ref="popup" type="center" title="新增满送计划" >
				<uni-section class="mb-10" title="活动设置" type="line">
					
					<view class="absolute">
						<view  >活动状态：</view>
						<switch @change="(res)=>{changeStatus(res,add.update_id)}" :checked="add.data.status==1" style="border-radius:0px"/>
					</view>
					
					<view class="add-box font13">
						<view class="add-goods floatleft"style="flex:1">
							<view class="riskTitle">计划名称：</view>
							<input
							v-model="add.data.nickname" 
							class="search-ipu" placeholder-class="placeholder-class"/>
							
							<view class="delete-ipu" v-if="add.data.nickname!=''" @click="add.data.nickname=''">
								<img src="../../static/img/delete-1.png"  ></img>
							</view>
							
						</view>

						
					</view>
					<view class="add-box font13">
						<view class="add-goods floatleft"style="flex:1">
							<view class="riskTitle" >活动时间：</view>
							<view class="flex flex1 search-ipu h100" style="margin-left: 0px;">
								<uni-datetime-picker type="daterange" class="date-box color-e40318  "
								v-model="add.data.date"
								:clear-icon="false" 
								></uni-datetime-picker>
								
							</view>
						</view>
						
						<view class="add-goods floatleft"style="flex:1">
							<view class="riskTitle" >其他备注：</view>
							
							<input
							v-model="add.data.descr" 
							class="search-ipu" placeholder-class="placeholder-class" />
							<view class="delete-ipu" v-if="add.data.descr!=''" @click="add.data.descr=''">
								<img src="../../static/img/delete-1.png"  ></img>
							</view>
						</view>
					</view>
				
					
				</uni-section>
				
				
				<uni-section class="mb-10" title="活动商品列表" type="line">
					<view class="absolute">
						
						<view class="rightButttom back_color" 
						@click="openSearchGoods(1)"
						>
							增加活动商品
						</view>
						
						
						<view class="rightButttom "
						@click="isShowHunhe=isShowHunhe==false?true:false"
						>
							增加混合赠送
						</view>
					</view>
					<view class="add-box font13">
						<!-- 列表区 -->
						<view class="content-box add-goods" style="width: inherit;">
							<view class="boxsss100" >
								<table v-if="planGoodsList.length>0">
									<!-- 表头 -->
									<thead>
										<tr >
											<th  class="centers " style="min-width: 20px;">
												序
											</th>
											<th  >
												活动的商品
											</th>
											<th  >
												活动的商品购满数量
											</th>
											<th  >
												赠送的商品
											</th>
											<th  >
												赠送的数量
											</th>
											<th >
												利润
											</th>
											<th class="centers" >
												操作
											</th>
										</tr>
									</thead>
									<tbody>
										<!-- 内容 -->
										<tr  
										:key="index" 
										v-for="(item,index) in planGoodsList"
										>
											<td  class="centers ">
												{{index+1}}
											</td>
											<td   class="bb4e00" @click="pageSend.value=item.goods_id,$refs.pageGoods.open()">
												{{item.name}}
											</td>
											<td   class="" >
												<view class="flex floatleft">
													<view class="riskTitle " >数量：</view>
													<input class="search-ipu" @input="GetProfit" v-model="item.count_man"/>
												</view>
											</td>
											<td   class=" hover" :class="item.count_plan>0?'bb4e00':''" @click="openSearchGoods(2,index)">
												{{item.goods_name_plan}}
											</td>
											<td   class="" >
												<view class="flex floatleft">
													<view class="riskTitle" >数量：</view>
													<input class="search-ipu" @input="GetProfit" v-model="item.count_plan"/>
												</view>
											</td>
											<td   class="" >
												<view class="flex font12">
													<view :style="GetMoneyProfit(item,item.goods.pifajia)<=0 ?'color: #ff0000;':'' ">
														批发价利润:￥{{GetMoneyProfit(item,item.goods.pifajia)}}
													</view>
												</view>
												
												<view class="flex font12">
													<view :style="GetMoneyProfit(item,item.goods.jinhuojia)<=0 ?'color: #ff0000;':'' ">
														进货价利润:￥{{GetMoneyProfit(item,item.goods.jinhuojia)}}
													</view>
												</view>
												
												<view class="flex font12">
													<view :style="GetMoneyProfit(item,item.goods.petail_price)<=0 ?'color: #ff0000;':'' ">
														零售价利润:￥{{GetMoneyProfit(item,item.goods.petail_price)}}
													</view>
												</view>
												
												<view class="flex font12" >
													<view :style="GetMoneyProfit(item,item.goods.level1)<=0 ?'color: #ff0000;':'' ">
														{{$routeData.GetLevelItem(1)['text']}}:￥{{GetMoneyProfit(item,item.goods.level1)}}
													</view>
												</view>
												
												<view class="flex font12" >
													<view :style="GetMoneyProfit(item,item.goods.level2)<=0 ?'color: #ff0000;':'' ">
														{{$routeData.GetLevelItem(2)['text']}}:￥{{GetMoneyProfit(item,item.goods.level2)}}
													</view>
												</view>
												
												
												<view class="flex font12" >
													<view :style="GetMoneyProfit(item,item.goods.level3)<=0 ?'color: #ff0000;':'' ">
														{{$routeData.GetLevelItem(3)['text']}}:￥{{GetMoneyProfit(item,item.goods.level3)}}
													</view>
												</view>
												
												
												<view class="flex font12" >
													<view :style="GetMoneyProfit(item,item.goods.level4)<=0 ?'color: #ff0000;':'' ">
														{{$routeData.GetLevelItem(4)['text']}}:￥{{GetMoneyProfit(item,item.goods.level4)}}
													</view>
												</view>
												<view class="flex font12" >
													<view :style="GetMoneyProfit(item,item.goods.level5)<=0 ?'color: #ff0000;':'' ">
														{{$routeData.GetLevelItem(5)['text']}}:￥{{GetMoneyProfit(item,item.goods.level5)}}
													</view>
												</view>
											</td>
											<td  class="centers hover" @click="deletePlanGoodsList(index)">
												删除
											</td>
										</tr>
									</tbody>
								</table>
								<!-- 暂无数据 -->
								<empty v-if="planGoodsList.length==0"></empty>
								<!-- end -->
								
							</view>
						</view>
						<!-- end -->
					</view>
				</uni-section>
				
				<uni-section class="mb-10" title="混合商品凑够满足后的设置" type="line" v-show="isShowHunhe">
					<!-- <view style="height: auto;" class="absolute">
						
						<view  
						style="height: auto;"
						>
							利润：{{sumProfit}}
						</view>
					</view> -->
					<view class="add-box font13">
						<view class="add-goods floatleft">
							<view class="riskTitle">购满个数(可选)：</view>
							
							<input 
							@input="GetProfit"
							v-model="add.data.count" 
							placeholder="输入客户单笔购满上面列表中商品的个数"
							type="number"
							class="search-ipu" placeholder-class="placeholder-class" />
							
							<view class="delete-ipu" v-if="add.data.count!=''" @click="add.data.count=''">
								<img src="../../static/img/delete-1.png"  ></img>
							</view>
						</view>
						<view class="tips">上面列表中的商品购买满足此数量后将赠送下面的赠品；支持混合搭配，赠送优先度低于上方的赠送设置</view>
					</view>
					<view class="add-box font13">
						<view class="add-goods"style="flex:1">
							<view class="riskTitle">赠送商品(可选)：</view>
							
							<view class="search-ipu justify" @click="openSearchGoods3()">
								{{add.data.goods_name}}
							</view>
							
							<view class="delete-ipu" v-if="add.data.goods_name!=''" @click="add.data.goods_name='',add.data.goods_id=''">
								<img src="../../static/img/delete-1.png"  ></img>
							</view>
						</view>
					</view>
							
					<view class="add-box font13">
						<view class="add-goods floatleft">
							<view class="riskTitle">赠送个数(可选)：</view>
							
							<input 
							@input="GetProfit"
							placeholder="输入需要赠送的商品个数"
							v-model="add.data.count_plan" 
							type="number"
							class="search-ipu" placeholder-class="placeholder-class" />
							
							<view class="delete-ipu" v-if="add.data.count_plan!=''" @click="add.data.count_plan=''">
								<img src="../../static/img/delete-1.png"  ></img>
							</view>
						</view>
						<view class="tips">赠送商品可获得赠送的数量</view>
					</view>
					
					
					
				</uni-section>
				
				<!-- $common.baseUrl.host+$common.baseUrl.static+ -->
				<view class="but-box">
					<view class="but-boxs">
						<view @click="$refs.popup.close"  class="add-but-close">
							取 消
						</view>
						<view @click="$common.noMultipleClicks('functionMain',functionMain)"  class="add-but-com">
							确定
						</view>
					</view>
				</view>
			</uni-popup>
			<!-- end -->

			<!-- 选择商品 遮罩层 -->
			<uni-popup ref="goods" type="center" title="选择商品">
				<!-- 数据列表 -->
				<view class="box-infos font12  " >
					
					<!-- 列表区 -->
					<view class="content-box " >
						<view class="boxsss40" >
							<view class="add-box">
								<view class="add-goods floatleft">
									<view class="riskTitle">搜索商品关键字</view>
									
									<input 
									v-model="goodsSearch.value" 
									@confirm="GetgoodsSearch(true)"
									class="search-ipu" placeholder-class="placeholder-class" />
									
									
									<view class="delete-ipu" v-if="goodsSearch.value!=''" @click="goodsSearch.value='',GetgoodsSearch(true)">
										<img src="../../static/img/delete-1.png"  ></img>
									</view>
								</view>
								<view @click="$common.noMultipleClicks('GetgoodsSearch',GetgoodsSearch,true)"  class="add-but-com">
									<img src="../../static/img/search.png" class="ico"></img>
									搜索
								</view>
							</view>
							
							<table v-if="goodsSearch.list.length>0">
								<!-- 表头 -->
								<thead>
									<tr >
										<th  class="centers ">
											<checkbox
												border-color="#333333" activeborderColor="#333333" activeBackgroundColor="#333"
												:checked="checkbox.select" 
												@click="choose_all"
												style="transform:scale(0.7);width: 5%;"
												
											/>
										</th>
										<th  class="centers " style="min-width: 20px;">
											序
										</th>
										<th  >
											商品
										</th>
										<th  class=" ">
											库存
										</th>
										<th  class=" ">
											批发价
										</th>
									</tr>
								</thead>
								<tbody>
									<checkbox-group @change="checkbox_change" style="display: contents;">
										<!-- 内容 -->
										<tr  
										:key="index" 
										@click="selectListIndexs(item)"
										v-for="(item,index) in goodsSearch.list" 
										:class="checkbox.checkbox_status.includes(item.id) ? 'goods-list-select':''"
										>
											<td  class="centers ">
												<checkbox
													:value="item.id.toString()" 
													:disabled="item.mp_grounding==1?false:true"
													border-color="#333333" activeborderColor="#333333" activeBackgroundColor="#333"
													:checked="checkbox.checkbox_status.includes(item.id)" 
													style="transform:scale(0.7);width: 5%;"
													class="border-right"
												/>
											</td>
											<td  class="centers ">
												{{index+1}}
											</td>
											<td   class=" " >
												{{item.name}}
											</td>
											<td   
											:style="{color:parseInt(item.margin)>0  ? '#2ab100':'#ff0000'}"
											>
												{{item.margin}}
											</td>
											<td   class="">
												￥{{item.pifajia}}
											</td>
									
										</tr>
									</checkbox-group>
								</tbody>
							</table>
							
							<!-- 暂无数据 -->
							<empty v-if="goodsSearch.list.length<=0"></empty>
							<!-- end -->
						</view>
						<view 
						@click="$common.noMultipleClicks('selectListIndex',selectListIndex,true)"  
						class="add-but-com"
						v-if="seleteGoodsType==1"
						>
							确定
						</view>
						<!-- 分页 -->
						<pages 
						:sum="add.page.sum"
						:current="add.page.nowPage"
						@updatePage="AddUpdatePage"
						></pages>
						<!-- end -->
					</view>
					<!-- end -->
				</view>
				<!-- 数据列表end -->
		
			</uni-popup>
			<!-- end -->

			<!-- 商品页面 -->
			<uni-popup ref="pageGoods" type="center" :title="pageSend.value">
				<shopping_admin :isPop="false" :OnPageSearchGoodsId="pageSend.value"  class="h100"></shopping_admin>
			</uni-popup>
			<!-- end -->

		</view>
	</view>
</template>

<script>
	import empty from "@/components/admin-components/empty.vue"
	import pages from "@/components/admin-components/pages.vue"
	import countdown from "@/components/cz-countdown/cz-countdown"
	import shopping_admin from "@/components/goods/goods.vue"
	export default{
		name:'sales_plan',
		components: {
			empty,pages,countdown,shopping_admin
		},
		data(){
			return{
				nowGoods:{},//当前的混合赠送的商品
				sumProfit:0,
				isShowHunhe:false,
				pageSend:{
					value:''
				},
				TabcheckedIndex:-1,//当前选中项
				resData:{},
				goodsSearch:{
					value:'',
					pifajia:'0',
					list :[],
				},
				goodsIndex:-1,//选择商品的赠送商品的索引
				seleteGoodsType:1,//1=选择活动商品模式；2=选择赠送商品模式
				add:{
					update_id:'',//修改计划的id
					data:{//欲要提交的商品
						start_time:'',//开始时间
						end_time:'',//结束时间
						descr:'',//计划备注
						status:'',//计划状态
						date:'',//计划时间
						
						nickname:'',//计划名称
						
						goods_id:'',//混合赠送的商品ID
						goods_name:'',//混合赠送的商品名称
						count:'',//混合凑够的数量
						count_plan:'',//混合凑够的赠送数量
					},
					page:{
						
						nowPage:1,//当前页数
						pageCount:1,//总页数
						maxCount:0,
						sum:0,
						pageCounts:15,
					},
				},
				checkbox:{//多选框
					checkbox_status:[],
					select_all:false,
				},
				planGoodsList:[//活动商品ID、名字的数组
					// {id:'',name:''}
				],
				page:{
					
					nowPage:1,//当前页数
					pageCount:1,//总页数
					maxCount:0,
					sum:0,
					pageCounts:15,
				},
			}
		},
		 // 此处定义传入的数据
		props: {
			OnPageSearchId: {
				type: String,
				default:''
			}
		},
		
		mounted(){
		},
		created() {
			this.getPlanMaxOut(true)
		},
		methods:{
			GetMoneyProfit(item,nowMoney){
				return Math.round((((nowMoney * item.count_man) - (item.goods.jinhuojia * item.count_man))- (item.goods_plan.jinhuojia * item.count_plan))*100)/100
			},
			GetProfit(){
				var list = this.planGoodsList
				var sum = 0
				for(var i=0;i<list.length;i++){
					sum += Math.round(
					(
						(
						(list[i].goods.pifajia * list[i].count_man) - (list[i].goods.jinhuojia * list[i].count_man))- 
						(list[i].goods_plan.jinhuojia * list[i].count_plan)
					
					)*100)/100
				}
				this.sumProfit = sum
				
			},
			timestampToDate(timestamp) {
			  var date = new Date(timestamp * 1000);  // 将时间戳转换为毫秒单位
			  var year = date.getFullYear();
			  var month = date.getMonth() + 1;
			  var day = date.getDate();
			  var hour = date.getHours();
			  var minute = date.getMinutes();
			  var second = date.getSeconds();
			  
			  var formattedDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
			  
			  return formattedDate;
			},
			/**
			 * 删除增加列表框内 的活动商品
			*/
			deletePlanGoodsList(index){
				if(this.add.update_id.length>0){
					this.$common.toast("不能删除正在修改中的计划")
					return
				}
				this.planGoodsList.splice(index,1)
			},
			/**
			 * 全选按钮的操作
			*/
			checkbox_change(e){
				this.checkbox.checkbox_status = e.detail.value
			},
			/**
			 * 全选中
			*/
			choose_all(){
				this.checkbox.checkbox_status = []
				if(this.checkbox.select_all == false){
					this.checkbox.select_all = true
					var tmpList = this.goodsSearch.list;
					for (var i=0;i<tmpList.length;i++) {
						this.checkbox.checkbox_status.push(tmpList[i].id)
					}
					
				}else{
					this.checkbox.select_all = false
					this.checkbox.checkbox_status = []
				}
			},
			
			// 取消全选中
			choos_all_close(){
				this.checkbox.select_all = false
				this.checkbox.checkbox_status = []
			},
			

			
	
			
			/**
			 * 活动-开关
			*/
			changeStatus(res,id){
				var that = this
				var status = res.detail.value==true? 1:2;
				if(id && id.length>0){
					this.add.data.status = status
					that.$common.get_request(
						{
							type:'plan_max_out_status',
							status:status,
							id:id
						},
						(res)=>{
							that.$common.showModal('提示',res.msg)
							that.getPlanMaxOut(true)
						},
						(res)=>{
							if(res && res.code!=0){
								that.add.data.status = 2
							}
						}
					);
				}
			},
		

			timestampToTime(timestamp) {
			  // 时间戳为10位需*1000，时间戳为13位不需乘1000
			  var date = new Date(timestamp * 1000);
			  var Y = date.getFullYear() + "-";
			  var M =
			    (date.getMonth() + 1 < 10
			      ? "0" + (date.getMonth() + 1)
			      : date.getMonth() + 1) + "-";
			  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
			  
			  return Y + M + D ;
			},
			
			/**
			 * 打开搜索商品窗口
			*/
			openSearchGoods(type,goodsIndex){
				
				if(this.goodsSearch.list.length==0){
					this.GetgoodsSearch(true)
				}
				this.seleteGoodsType = type
				this.goodsIndex = goodsIndex
				this.$refs.goods.open()
			},
			/**
			 * 打开搜索商品窗口2
			*/
			openSearchGoods3(){
				
				if(this.goodsSearch.list.length==0){
					this.GetgoodsSearch(true)
				}
				this.seleteGoodsType = 3
				this.$refs.goods.open()
			},
			/**
			 * 打开增加、修改窗口
			 * update_id : 可能为空；即是新增
			*/
			addShow(item){
				let that = this
				that.add.data.restrict = []
				if(item.id && item.id!=""){
					if(item.count_plan>0){
						that.isShowHunhe = true
					}
					
					//把需要编辑的内容赋值到弹出窗处
					that.add.update_id = item.id
					that.add.data.date = []
					that.add.data.date.push(that.timestampToTime(item.start_time))
					that.add.data.date.push(that.timestampToTime(item.end_time))
					that.add.data.descr= item.descr
					that.add.data.end_time= ''
					
					that.planGoodsList = item.GoodsList
					that.add.data.goods_name = item.goods_id_name
					that.add.data.goods_id   = item.goods_id_plan
					that.add.data.count = item.count
					that.add.data.count_plan   = item.count_plan
					
					that.add.data.start_time= ''
					that.add.data.status    = item.status
					that.goodsSearch.pifajia = item.pifajia
					that.add.data.restrict  = item.restricts
					
					that.add.data.nickname  = item.nickname
					that.nowGoods = item.goods_plan
					
				}else{
					that.isShowHunhe = false
					
					
					that.nowGoods = {}
					that.add.data.goods_name = ''
					that.add.data.goods_id   = ''
					that.add.data.count      = ''
					that.add.data.count_plan =''
					that.add.update_id    = ''
					that.add.data.date    = []
					that.add.data.descr   = ''
					that.add.data.end_time= ''
					
					
					that.planGoodsList    = []
					
					
					that.add.data.start_time = ''
					that.add.data.status     = ''
					that.goodsSearch.pifajia =  ''
					
					
					
					that.add.data.nickname   = ''
				}
				that.$refs.popup.open()
			},

			/**
			 * 搜索商品 分页器回调
			*/
			AddUpdatePage(pageName,pageCount){
				var that = this
				that.add.page.nowPage = pageName
				that.add.page.pageCounts = pageCount
				that.GetgoodsSearch(false)
				
			},
			/**
			 * 搜索商品
			*/
			GetgoodsSearch(isUpdatePage=true){
				var that = this
		
				that.add.page.nowPage = isUpdatePage == true ? 1:that.add.page.nowPage;
				
				that.$common.get_request(
					{
						type:'goods_list',
						search:that.goodsSearch.value,//搜索内容
						pages:that.add.page.nowPage,//当前位于页数
						page_count:that.add.page.pageCounts,//当前请求页的数量
					},
					(res)=>{
						that.goodsSearch.list = res.list
						that.add.page.pageCount  = res.pageCount
						that.add.page.sum  = res.sum
						if(isUpdatePage == true){
						that.add.page.nowPage  = 1
						}
						that.add.page.maxCount  = res.maxCount
						
						that.choos_all_close()
						
					}
				);
			},
			/**
			 * 选中商品
			 * type : goods_list|goods_search
			*/
			selectListIndex(){
				var that = this
				if(that.checkbox.checkbox_status.length==0){
					that.$common.toast("未有选中需要的，失败。")
					return
				}
				//id转换名字
				that.$common.get_request(
					{
						type:'goodsIdGetGoodsName',
						data:JSON.stringify(that.checkbox.checkbox_status),
					},
					(res)=>{
						that.checkbox.checkbox_status = []
						var list = []
						for(var i=0;i<res.list.length;i++){
							list.push({
								id : res.list[i].id,
								name : res.list[i].name,
								goods_id_plan : res.list[i].id,
								goods_name_plan : res.list[i].name,
								goods : res.list[i],
								goods_plan:res.list[i],
							})
						}
						that.planGoodsList.push(...list);
						
						that.$refs.goods.close()
						that.choos_all_close()
					}
				);
			},
			/**
			 * 选中商品，被赠送的
			*/
			selectListIndexs(item){
				if(item.mp_grounding!=1){
					this.$common.showModal("当前商品未上架小程序无法增加")
					return
				}
				if(this.seleteGoodsType==2){
					this.planGoodsList[this.goodsIndex].goods_id_plan = item.id
					this.planGoodsList[this.goodsIndex].goods_name_plan = item.name
					this.$refs.goods.close()
					
				}else if(this.seleteGoodsType==3){
					this.add.data.goods_id = item.id
					this.add.data.goods_name = item.name
					this.nowGoods = item
					this.$refs.goods.close()
				}
			},
			/**
			 * 分页器回调
			*/
			updatePage(pageName,pageCount){
				var that = this
				that.page.nowPage = pageName
				that.page.pageCounts = pageCount
				that.getPlanMaxOut(false)
			},
			/**
			 * 读取
			 * 
			*/
			getPlanMaxOut(isUpdatePage=true){
				var that = this
				
				that.page.nowPage = isUpdatePage == true ? 1:that.page.nowPage;
				that.$common.get_request(
					{
						type:'getPlanMaxOut',
						pages:that.page.nowPage,//当前位于页数
						page_count:that.page.pageCounts,//当前请求页的数量
						plan_id:that.OnPageSearchId
					},
					(res)=>{
						that.resData = res
						
						that.page.sum  = res.sum
						if(isUpdatePage == true){
						that.page.nowPage  = 1
						}
					}
				);
			},

			functionMain(){
				if(this.add.data.date.length<2){
					this.$common.showModal('提示',"请选择计划的时间后再试")
					return
				}
				if(this.planGoodsList.length==0){
					this.$common.showModal('提示',"请选中需要参与活动的商品后再试")
					return
				}
				// if(this.add.data.status.length==0){
				// 	that.$common.showModal('提示',"请选择计划 开关 后再试")
				// 	return
				// }
			

				if(Math.floor(this.add.data.goods_id)>0 && this.add.data.count<=0){
					this.$common.showModal('提示',"当前选择了混合购买商品赠送模式，但混合购买的满足数量未填写。")
					return
				}

				if(this.checkSend() == false){
					this.$common.showModal('提示',"经检查列表框中的活动商品的购满数量 或 赠送数量未输入完整！")
					return
				}
				
				this.fun_plan()
				
			},
			//准备前的检查;没有问题返回true
			checkSend(){
				var success = true;
				for(var i=0;i<this.planGoodsList.length;i++){
					if(this.planGoodsList[i].count_man || this.planGoodsList[i].count_man<=0){
						return this.planGoodsList[i].name+' 的';
					}else if(this.planGoodsList[i].count_plan || this.planGoodsList[i].count_plan<=0){
						return this.planGoodsList[i].name;
					}
				}
				return true
			},
			/**
			 * 保存、修改方法
			*/
			fun_plan(){
				var that = this
				
				let data       = that.add.data

				data.planGoodsList = JSON.stringify(that.planGoodsList)
				data.update_id = that.add.update_id
				data.start_time= that.add.data.date[0]
				data.end_time  = that.add.data.date[1]
				data.type      = that.add.update_id==''?'plan_max_out_sva':'plan_max_out_update'
				//如果包含了http,就是修改的。
				
				that.$common.get_request(
					data,
					(res)=>{
						uni.showModal({
							content:res.msg,
							showCancel:false,
							success: () => {
								that.$refs.popup.close()
								that.getPlanMaxOut(true)
							}
						})
					}
				);
			},
			
		}
	}
</script>

<style>
	.absolute{
		position: absolute;
		top: 12px;
		right: 10px;
		width: auto;
		min-width: auto;
		padding: 5px;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.marginAuto{
		display: flex;
		margin: 20px auto 0px auto;
		width: 30px;
	}
	.mb-10{
		position: relative;
		padding: 10px;
	}
</style>
